package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.BusServiceItem;
import cn.wolfcode.business.domain.vo.AuditInfoVO;
import cn.wolfcode.business.domain.vo.AuditVo;
import cn.wolfcode.business.service.IBusServiceItemService;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务项Controller
 * 
 * @author wolfcode
 * @date 2025-09-19
 */
@RestController
@RequestMapping("/business/serviceItem")
public class BusServiceItemController extends BaseController
{
    @Autowired
    private IBusServiceItemService busServiceItemService;

    /**
     * 查询服务项列表
     */
    @PreAuthorize("@ss.hasPermi('business:serviceItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusServiceItem busServiceItem)
    {
        startPage();
        List<BusServiceItem> list = busServiceItemService.selectBusServiceItemList(busServiceItem);
        return getDataTable(list);
    }

    /**
     * 导出服务项列表
     */
    @PreAuthorize("@ss.hasPermi('business:serviceItem:export')")
    @Log(title = "服务项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusServiceItem busServiceItem)
    {
        List<BusServiceItem> list = busServiceItemService.selectBusServiceItemList(busServiceItem);
        ExcelUtil<BusServiceItem> util = new ExcelUtil<BusServiceItem>(BusServiceItem.class);
        util.exportExcel(response, list, "服务项数据");
    }

    /**
     * 获取服务项详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:serviceItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busServiceItemService.selectBusServiceItemById(id));
    }

    /**
     * 新增服务项
     */
    @PreAuthorize("@ss.hasPermi('business:serviceItem:add')")
    @Log(title = "服务项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusServiceItem busServiceItem)
    {
        return toAjax(busServiceItemService.insertBusServiceItem(busServiceItem));
    }

    /**
     * 修改服务项
     */
    @PreAuthorize("@ss.hasPermi('business:serviceItem:edit')")
    @Log(title = "服务项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusServiceItem busServiceItem)
    {
        return toAjax(busServiceItemService.updateBusServiceItem(busServiceItem));
    }

    /**
     * 删除服务项
     */
    @PreAuthorize("@ss.hasPermi('business:serviceItem:remove')")
    @Log(title = "服务项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busServiceItemService.deleteBusServiceItemByIds(ids));
    }

    @PatchMapping(value = "/{id}",headers = "cmd=on")
    public AjaxResult saleOnHandle(@PathVariable Long id)
    {
        return toAjax(busServiceItemService.saleOnHandle(id));
    }
    @PatchMapping(value = "/{id}",headers = "cmd=down")
    public AjaxResult saleDownHandle(@PathVariable Long id)
    {
        return toAjax(busServiceItemService.saleDownHandle(id));
    }

    @GetMapping(value = "/list",headers = "cmd=list")
    public AjaxResult list1(BusServiceItem busServiceItem){
        List<BusServiceItem> list = busServiceItemService.selectBusServiceItemList(busServiceItem);
        return AjaxResult.success(list);
    }
    //查询审批信息
    @GetMapping("/{id}/auditInfo")
    public AjaxResult auditInfo(@PathVariable Long id){
        AuditInfoVO vo = busServiceItemService.createAuditInfo(id);
        return AjaxResult.success(vo);
    }
    //发起审批
    @PostMapping("/startAudit")
    public AjaxResult startAudit(@RequestBody AuditVo vo){
        return AjaxResult.success(busServiceItemService.startAudit(vo));
    }

}
